package com.qsl.ssyx.product.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qsl.ssyx.common.result.Result;
import com.qsl.ssyx.model.product.Attr;
import com.qsl.ssyx.product.service.AttrGroupService;
import com.qsl.ssyx.product.service.AttrService;
import com.qsl.ssyx.vo.product.AttrGroupQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 商品属性 前端控制器
 * </p>
 *
 * @author 青衫泪
 * @since 2023-08-10
 */
@Api(tags = "商品属性分组接口")
@RestController
@RequestMapping("/admin/product/attr")
public class AttrController {

    @Autowired
    private AttrService attrService;

    @ApiOperation("根据groupId查询")
    @GetMapping("{groupId}")
    public Result getAttrByGroupId(@ApiParam(value = "商品属性分组id") @PathVariable Integer groupId) {
        List<Attr> model = attrService.getAttrByGroupId(groupId);
        return Result.ok(model);
    }

    @ApiOperation("新增")
    @PostMapping("save")
    public Result save(@RequestBody Attr attr) {
        boolean flag = attrService.save(attr);

        return Result.ok(flag);
    }

    @ApiOperation("根据Id查询")
    @GetMapping("getById/{id}")
    public Result save(@ApiParam(value = "id") @PathVariable("id") Integer Id) {
        Attr attr = attrService.getById(Id);
        return Result.ok(attr);
    }

    @ApiOperation("修改")
    @PutMapping("update")
    public Result update(@RequestBody Attr attr) {
        boolean flag = attrService.updateById(attr);
        return Result.ok(flag);
    }

    @ApiOperation("删除")
    @DeleteMapping("remove/{Id}")
    public Result remove(@PathVariable Integer Id) {
        boolean flag = attrService.removeById(Id);
        return Result.ok(flag);
    }

    @ApiOperation("批量删除")
    @DeleteMapping("batchRemove")
    public Result batchRemove(@RequestBody List<Integer> idList) {
        boolean flag = attrService.removeByIds(idList);
        return Result.ok(idList);
    }


}

